<template>
  <div class="video-card">
    <t-card :title="video.title" :subtitle="formattedDate" hoverable @click="playVideo">
      <div class="video-thumbnail" @click="playVideo">
        <img :src="video.thumbnail_url" alt="视频缩略图" />
        <t-icon name="play-circle-filled" class="play-icon" />
      </div>
      <div class="video-info">
        <p>{{ video.description }}</p>
      </div>
    </t-card>
  </div>
</template>

<script>
export default {
  name: 'VideoCard',
  props: {
    video: {
      type: Object,
      required: true,
    },
  },
  computed: {
    formattedDate() {
      return new Date(this.video.publish_date).toLocaleDateString();
    },
  },
  methods: {
    playVideo() {
      this.$emit('playVideo', this.video);
    },
  },
};
</script>

<style scoped>
.video-card {
  cursor: pointer;
}

.video-thumbnail {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 Aspect Ratio */
  overflow: hidden;
}

.video-thumbnail img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px;
  color: rgba(255, 255, 255, 0.8);
}

.video-info {
  margin-top: 10px;
}

.video-info p {
  margin: 0;
  color: #606266;
  font-size: 14px;
  line-height: 1.5;
}
</style>
